package com.dp.mallchat;

/**
 * @Author: dupeng
 * @CreateTime: 2024-08-15  20:43
 * @Description: TODO
 */
public class Solution {
    public int maxScore(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        int[][] dp = new int[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int fromTop = (i > 0)? dp[i - 1][j] : 0;
                int fromLeft = (j > 0)? dp[i][j - 1] : 0;

                dp[i][j] = Math.max(fromTop, fromLeft) + grid[i][j];
            }
        }

        int maxScore = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                maxScore = Math.max(maxScore, dp[i][j]);
            }
        }

        return maxScore;
    }

    public static void main(String[] args) {// 24 24 24,10
        int[][][] grid = {{{9, 5, 7, 3}, {8, 9, 6, 1}, {6, 7, 14, 3}, {2, 5, 3, 1}},{{1, 2, 3, 4}, {5, 6}}};
//        Solution solution = new Solution();
//        System.out.println(solution.maxScore(grid));

        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                for (int k = 0; k < grid[i][j].length; k++) {
                    System.out.print(grid[i][j][k]+",");
                }
                System.out.println();

            }
            System.out.println();
        }

    }
}